<%-- 
    Document   : ChangePassword
    Created on : Nov 23, 2012, 9:50:07 AM
    Author     : vupttse
--%>

<%@page import="assignment2.stub.UsersTbl_Stub"%>
<%@page import="assignment2.data.Users"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="css/modern.css" rel="stylesheet">
        <link href="css/modern-responsive.css" rel="stylesheet">
        <link href="css/site.css" rel="stylesheet" type="text/css">

        <script src="js/jquery-1.8.2.min.js"></script>
        <script src="js/google-analytics.js"></script>
        <script src="js/github.info.js"></script>
        <script src="js/sharrre/jquery.sharrre-1.3.4.min.js"></script>
        <script src="js/carousel.js"></script>
        <script src="js/dropdown.js"></script>
        <script src="js/slider.js"></script>
        <script src="js/hover.js"></script>
        <script src="js/pagecontrol.js"></script>
        <script src="js/accordion.js"></script>

        <script>
            //            Validate the input of the form when submit
            function validateForm()
            {
                var x=document.forms["ChangePassForm"]["password"].value;
                var y=document.forms["ChangePassForm"]["re-password"].value;
                if (x==null || x=="" || y==null || y=="" || x!=y)
                {
                    alert("Error! Check the re-password!");
                    return false;
                }
            }
        </script>
    </head>
    <body>
        <div class="page">
            <jsp:include page="Navigation.jsp"></jsp:include>
                <div class="page-region">
                    <div class="page-region-content" style="min-height: 500px">
                        <div class="span8" style="margin-left: 20px; padding-left: 20px;">
                            <h1>Change Password</h1>
                            <form name="ChangePassForm" action="" method="post" onsubmit="return validateForm()">
                                <table class="span7">
                                    <tr>
                                        <td>Enter new password:</td>
                                        <td><div class="input-control password">
                                                <input type="password" name="password" />
                                                <span class="helper"></span>
                                            </div></td>
                                    </tr>
                                    <tr>
                                        <td>Enter  re-password:</td>
                                        <td><div class="input-control password">
                                                <input type="password" name="re-password" />
                                                <span class="helper"></span>
                                            </div></td>
                                    </tr>
                                    <tr>
                                        <td>Enter new password:</td>
                                        <td><input type="submit" value="Change">
                                            <input type="reset" value="Reset"></td>
                                    </tr>
                                </table>                            
                            </form>
                        <%                            
                            Users user = (Users) session.getAttribute("currentUser");
                            if (user == null) {
                                response.sendRedirect("LoginPage.jsp");
                            } else {
                                String password = request.getParameter("password");
                                if (password != null) {
                                    Users usernew = new Users(user.getUserName(), password);
                                    UsersTbl_Stub usersTbl_Stub = new UsersTbl_Stub();
                                    if (usersTbl_Stub.changePassword(usernew)) {%>
                                 <h3>Change password successfully!</h3>                                   
                        <%}
                                }
                            }
                        %>
                    </div>
                </div>
            </div>
            <%@include  file="footer.html" %>
        </div>
    </body>
</html>
